/**
 * 
 * @author Sunix
 * @date   2013-5-26
 * @Email  SunixSky@gmail.com
 * 
 */	
package business.avatar{
	import com.greensock.TweenLite;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import br.com.stimuli.loading.BulkLoader;
	import br.com.stimuli.loading.BulkProgressEvent;
	
	import core.General;
	
	public class BaseAvatar extends Sprite{
		
		private var _loader:BulkLoader;
		
		protected var id:uint;
		protected var i:uint = 0;
		
		public function BaseAvatar(value:uint){
			id = value;
			veiwInit();
			
			addEventListener(MouseEvent.CLICK,onClick);
		}
		
		protected function onClick(event:MouseEvent):void{
		//	doHert();
			move();
		}
		
		private function move():void{
			TweenLite.to(this,0.2,{scaleX:1.1,scaleY:1.1,y:y + 100,onComplete:stop});
		}
		
		private function stop():void{
			scaleX = 1;
			scaleY = 1;
		}
		
		private function doHert():void{
			i = 0;
			toRight();
		}
		
		private function reset():void{
			x = 0;
		}
		
		private function toRight():void{
			i++;
			if(i>3){
				reset();
				return;
			}
				
			TweenLite.to(this,0.01,{x:10,onComplete:toLeft});
		}
		
		private function toLeft():void{
			TweenLite.to(this,0.01,{x:-10,onComplete:toRight});
		}
		
		protected function veiwInit():void{
			loader.add('assets/image/avatar/' + id+ '.png',{"id":"avatar"});
			loader.addEventListener(BulkLoader.COMPLETE,complete);
			loader.start();
		}
		
		protected function complete(event:BulkProgressEvent):void{
			var bm:Bitmap = loader.getBitmap("avatar");
			bm.smoothing = true;
			addChild(bm);
		}
		
		public function get loader():BulkLoader{
			if(!_loader)
				_loader = General.loader;
			return _loader;
		}
	}
}